import React, { createContext, useState, useEffect, useRef } from 'react';
import HeadTop from '@/components/HeadTop';
import ListItem from '@/components/ListItem';
import { listFields } from '../_parts/const';
import ApiIndex from '@/api/index'
import "./index.less"

function Index ({ history }) {
    const [List, setList] = useState([]); //列表

    useEffect(() => {
        fetchData()
    }, []);

    const fetchData = () => {
        ApiIndex.getList({
            type: 'RETURNED',
            status: 'CONFIRMED'
        }).then(res => {
            if (!res.data.code) {
                setList(res.data.data)
            }
        })
    }

    return (
        <div className='page-wrapper'>
            <HeadTop
                title="备件归还"
                history={history}
            ></HeadTop>
            <div className="page-body">
                {
                    List.length > 0 ?
                        List.map(el => <ListItem
                            key={el.id}
                            item={el}
                            history={history}
                            listFields={listFields}
                            detailUrl="/returnDetail"
                        ></ListItem>)
                        : <div className='no-list-data'>
                            无更多数据
                        </div>
                }
            </div>
        </div>
    );
}

export default Index;
